home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / matrixc.zip / 3DTEST.C < prev    next >
C/C++ Source or Header  |  1990-05-10  |  2KB  |  122 lines

  1. /* Example of use of 3D routines to translate a cube on X and Y axes */
  2. /* To make 3dtest.exe use
  3.    make 3dtest.mak       */
  4. /* Written by Nigel Salt */
  5.  
  6. #include <3d.h>
  7. #include <graph.h>
  8.  
  9. double dmatA[4][4];
  10. matrix matA={4,4,&dmatA[0][0]};
  11.  
  12. double dmatB[4][4];
  13. matrix matB={4,4,&dmatB[0][0]};
  14.  
  15. double dmatC[4][4];
  16. matrix matC={4,4,&dmatC[0][0]};
  17.  
  18. double dmatD[4][4];
  19. matrix matD={4,4,&dmatD[0][0]};
  20.  
  21. double dmatE[4][4];
  22. matrix matE={4,4,&dmatE[0][0]};
  23.  
  24. double dmatF[4][4];
  25. matrix matF={4,4,&dmatF[0][0]};
  26.  
  27. double dmatG[4][4];
  28. matrix matG={4,4,&dmatG[0][0]};
  29.  
  30. double dmatH[4][4];
  31. matrix matH={4,4,&dmatH[0][0]};
  32.  
  33. double dmatI[4][4];
  34. matrix matI={4,4,&dmatI[0][0]};
  35.  
  36. double dmatJ[4][4];
  37. matrix matJ={4,4,&dmatJ[0][0]};
  38.  
  39. double cubep[8][3]=
  40. {
  41.   1,1,1,
  42.   1,1,-1,
  43.   1,-1,-1,
  44.   1,-1,1,
  45.   -1,1,1,
  46.   -1,1,-1,
  47.   -1,-1,-1,
  48.   -1,-1,1
  49. };
  50. int cubel[12][2]=
  51. {
  52.   1,2,
  53.   2,3,
  54.   3,4,
  55.   4,1,
  56.   5,6,
  57.   6,7,
  58.   7,8,
  59.   8,5,
  60.   1,5,
  61.   2,6,
  62.   3,7,
  63.   4,8
  64. };
  65. object cube=
  66. {
  67.   8.0,12.0,&cubep[0][0],&cubel[0][0]
  68. };
  69.  
  70. /* Test 3d graphics functions
  71.    Compile using make
  72.    make 3dtest.mak       */
  73. /* Written by Nigel Salt */
  74. double cubep2[8][3];
  75. int cubel2[12][2];
  76. object cube2=
  77. {
  78.   8.0,12.0,&cubep2[0][0],&cubel2[0][0]
  79. };
  80.  
  81. main()
  82. {
  83.   int i,j,axis;
  84.   double inc;
  85.   char buff[80];
  86.   init3d();
  87.   scale3(&matA,25,25,25);
  88.   objtran(&cube,&matA);
  89.   rot3(&matA,pi/8,2);
  90.   objtran(&cube,&matA);
  91.   rot3(&matA,pi/8,1);
  92.   objtran(&cube,&matA);
  93.  
  94.   for (j=0;j<4;j++)
  95.     {
  96.     axis=j%2;
  97.     inc=(j<2?1.0:-1.0);
  98.     tran3(&matA,(axis==0?inc:0),(axis==1?inc:0),0);
  99.     _settextposition(30,0);
  100.     sprintf(buff,"%c TRAN",'X'+axis);
  101.     _outtext(buff);
  102.     for (i=0;i<100;i++)
  103.       {
  104.       _setcolor(15);
  105.       objdraw(&cube);
  106.       objcop(&cube,&cube2);
  107.       objtran(&cube,&matA);
  108.       _setcolor(0);
  109.       objdraw(&cube2);
  110.       }
  111.     }
  112.   _setvideomode(_DEFAULTMODE);
  113. }
  114.  
  115. wait()
  116. {
  117.  _settextposition(30,0);
  118.  _outtext("PRESS KEY");
  119.  getch();
  120.  _clearscreen(_GCLEARSCREEN);
  121. }
  122.